client_list = {};

function onStart(path)
    print("[lastCitadel] Server "..path.." started.");
end

function onStop(path)
    print("[lastCitadel] Server"..path.." ended.");
end

function onConnection(client,response,...)
    client_list[client] = {writer=client.writer,x=0,y=0,nickname="",uid=0,ready=0};
    print('[lastCitadel] There Someone connected in');
end

function onDisconnection(client)
    target = client_list[client];
    broadcast(client,0,"leave",target.uid);
    client_list[client] = nil;
    print('[lastCitadel] Someone disconnected.');
end

function ready(client)
    target = client_list[client];
    if target==nil then
        return 0;
    end
    target["ready"] = 1;
    return 1;
end

function broadcast(cli,all,command,...)
    for client,obj in pairs(client_list) do
        if obj["ready"]==1 and (all==1 or (all==0 and client~=cli)) then
            obj["writer"]:writeAMFMessage(command,arg);
        end
    end
    return 1;
end





